package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    /**
     * @description: 新增地址
     * @author: tanbobin
     * @date: 2024/6/6 11:22
     * @param:
     * @param addressBook
     * @return:
     **/
    void add(AddressBook addressBook);

    /**
     * @description: addressBookMapper.queryList();
     * @author: tanbobin
     * @date: 2024/6/6 11:33
     * @param:
     * @return:
     * @return java.util.List<com.sky.entity.AddressBook>
     **/
    @Select("select * from address_book")
    List<AddressBook> queryList();

    /**
     * @description: 根据 用户id修改 默认地址
     * @author: tanbobin
     * @date: 2024/6/6 11:46
     * @param:
     * @param addressBook
     * @return:
     **/
    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateDefaultAddress(AddressBook addressBook);

    /**
     * @description: 设置默认地址
     * @author: tanbobin
     * @date: 2024/6/6 11:51
     * @param:
     * @param addressBook
     * @return:
     **/
    @Update("update address_book set is_default = #{isDefault} where id = #{id};")
    void setDefaultAddress(AddressBook addressBook);

    /**
     * @description: 查询默认地址
     * @author: tanbobin
     * @date: 2024/6/6 12:44
     * @param:
     * @param addressBook
     * @return:
     * @return com.sky.entity.AddressBook
     **/
    AddressBook queryAddress(AddressBook addressBook);

    /**
     * @description: 根据id修改地址
     * @author: tanbobin
     * @date: 2024/6/6 13:07
     * @param:
     * @param addressBook
     * @return:
     **/
    void updateAddress(AddressBook addressBook);

    /**
     * @description: 根据id删除地址
     * @author: tanbobin
     * @date: 2024/6/6 13:24
     * @param:
     * @param id
     * @return:
     **/
    @Delete("delete from address_book where id = #{id}")
    void deleteAddress(Long id);

    /**
     * @description: 根据id查询地址
     * @author: tanbobin
     * @date: 2024/6/6 14:06
     * @param:
     * @param id
     * @return:
     * @return com.sky.entity.AddressBook
     **/
    @Select("select * from address_book where id = #{id}")
    AddressBook queryAddressById(Long id);
}
